export const towerInfoMixin = {
  data () {
    return {
      dataList: {
        query: '',
        pagenum: 1,
        pagesize: 7
      },
      total: null,
      studentList: [],
      activeName: '1'
    }
  },
  created () {
    this.getTowerList()
  },
  methods: {
    // 给表格添加索引
    indexMethod (index) {
      return (index + 1)
    },
    handleSizeChange (size) {
      // console.log(size)
      // console.log(`每页 ${size} 条`)
      this.dataList.pagesize = size
      // 每当这个页面显示的条数发生改变，就应该通过数据请求重新拿到数据
      // 重新数据请求代码在这写
      // console.log(this.$refs.towerRef[0].data[0].tower)
      const towerItem = this.$refs.towerRef[0].data[0].tower
      this.getTowerList(undefined, null, towerItem)
    },
    handleCurrentChange (currentPage) {
      // console.log(`当前页: ${currentPage}`)
      this.dataList.pagenum = currentPage
      // 这里也需要重新请求一下数据
      // console.log(this.$refs.towerRef[0].data[0].tower)
      const towerItem = this.$refs.towerRef[0].data[0].tower
      this.getTowerList(undefined, null, towerItem)
    },
    // 搜索学生
    async serchStudentClick () {
      const { data: res } = await this.$axios.get('/student/findStudent', {
        params: {
          query: this.dataList.query,
          tower: this.currTower
        }
      })
      // console.log(res)
      if (res.meta.code !== 200) {
        return this.$message.warning(res.meta.msg)
      } else {
        this.studentList = res.result
      }
    }
  }
}
